package com.zxy.ziems.server.log.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zxy.ziems.server.log.convert.DataRecordLogConvert;
import com.zxy.ziems.server.log.mapper.DataRecordLogMapper;
import com.zxy.ziems.server.log.pojo.entity.DataRecordEntity;
import com.zxy.ziems.server.log.pojo.entity.DataRecordLogEntity;
import com.zxy.ziems.server.log.pojo.vo.DataRecordLogVO;
import com.zxy.ziems.server.log.service.DataRecordLogService;
import com.zxy.ziems.server.mybatis.core.service.ServiceImplX;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class DataRecordLogServiceImpl extends ServiceImplX<DataRecordLogMapper, DataRecordLogEntity> implements DataRecordLogService {

    @Transactional(propagation = Propagation.MANDATORY)
    @Override
    public void adds(List<DataRecordLogEntity> logs) {
        saveBatch(logs);
    }

    @Override
    public List<DataRecordLogVO> getByDataRecordId(String dataRecordId) {
        QueryWrapper<DataRecordLogEntity> param = new QueryWrapper<>();
        param.lambda().eq(DataRecordLogEntity::getDataRecordId, dataRecordId);
        List<DataRecordLogEntity> dataRecordLogEntities = baseMapper.selectList(param);
        return dataRecordLogEntities.stream().map(m -> DataRecordLogConvert.INSTANCE.entity2Vo(m)).collect(Collectors.toList());
    }
}
